import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 商品总数
    count: 0,
    // 总价格
    zprice: 0
  },
  mutations: {
    getcoutn(state) {
      var snum = 0
      var pricesum = 0
      const locainlist = JSON.parse(localStorage.getItem('Cart'))
      if (!locainlist) return
      locainlist.forEach(item => {
        snum += item.num
        pricesum += (parseInt(item.pirce)*item.num)
      })
      state.count = snum
      state.zprice = pricesum
    }
  },
  actions: {
  },
  getters: {
  }
})
